// Automatic Answer
// UVa ID: 11547
// Verdict: Accepted
// Submission Date: 2017-12-17
// UVa Run Time: 0.000s
//
// 版权所有（C）2017，邱秋。metaphysis # yeah dot net

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int cases, n;
    cin >> cases;

    for (int c = 1; c <= cases; c++)
    {
        cin >> n;
        n = 315 * n + 36962;
        n = abs(n);
        n /= 10;
        cout << (n % 10) << '\n';
    }

    return 0;
}
